package com.bdbit.ChargingStation.config;

import org.slf4j.LoggerFactory;
import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.Logger;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;

@Configuration
public class LoggingConfig {
    
    @Value("${logging.detail.mapping.enabled:false}")
    private boolean detailedMappingEnabled;
    
    @PostConstruct
    public void initLogging() {
        // 获取 BeanPropertyRowMapper 的日志记录器
        Logger rowMapperLogger = (Logger) LoggerFactory.getLogger("org.springframework.jdbc.core.BeanPropertyRowMapper");
        
        // 根据配置设置日志级别
        if (detailedMappingEnabled) {
            rowMapperLogger.setLevel(Level.DEBUG);
            LoggerFactory.getLogger(LoggingConfig.class).info("详细映射日志已开启");
        } else {
            rowMapperLogger.setLevel(Level.OFF);
            LoggerFactory.getLogger(LoggingConfig.class).info("详细映射日志已关闭");
        }
    }
}